package com.qf.sdk.controller;

import com.qf.sdk.cache.CpCache;
import com.qf.sdk.cache.GameCache;
import com.qf.sdk.cache.LocalCache;
import com.qf.sdk.cache.ProCache;
import com.qf.sdk.entity.Cp;
import com.qf.sdk.entity.Game;
import com.qf.sdk.entity.LocalePrompt;
import com.qf.sdk.entity.PromotionChannel;
import com.qf.sdk.view.ResponseVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * 2019/12/24
 * 郭程鹏
 * springcloud-App
 * 面向代码面向君,不负时光不负卿
 */
@RestController
@RequestMapping("/sdkcore")
public class GameController {


    @RequestMapping("/common/init.html")
    public ResponseVO commonInit(@RequestParam(name = "cpid") Integer cpId,@RequestParam(name = "seqnum") Integer seqnum){
        Game game = GameCache.getGameMap(cpId, seqnum);
        //封装视图
        ResponseVO responseVO = new ResponseVO();
        if (game==null){
            return responseVO;
        }else {
            HashMap<String, String> map = new HashMap<>();
            map.put("status",game.getRepairStatus().toString());
            map.put("context",game.getRepairContent());
            map.put("name",game.getName());
            responseVO.setSuccess(true);
            responseVO.setTicket(null);
            responseVO.setErrorCode(200);
            responseVO.setBusinessResult(map);
        }
        return responseVO;
    }
    @RequestMapping("/common/cp.html")
    public ResponseVO cpInit(@RequestParam(name = "cpid") Integer cpId){
        Cp cp = CpCache.getCpMap(cpId);
        //封装视图
        ResponseVO responseVO = new ResponseVO();
        if (cp==null){
            return responseVO;
        }else {
            HashMap<String, String> map = new HashMap<>();
            map.put("id",cp.getId().toString());
            map.put("name",cp.getName());
            map.put("secretKey",cp.getSecretKey());
            map.put("status",cp.getStatus().toString());
            responseVO.setSuccess(true);
            responseVO.setTicket(null);
            responseVO.setErrorCode(200);
            responseVO.setBusinessResult(map);
        }
        return responseVO;
    }

    @RequestMapping("/common/pro.html")
    public ResponseVO proInit(@RequestParam(name = "id") Integer id){
        PromotionChannel channel = ProCache.getProMap(id);
        //封装视图
        ResponseVO responseVO = new ResponseVO();
        if (channel==null){
            return responseVO;
        }else {
            HashMap<String, String> map = new HashMap<>();
            map.put("id",channel.getId().toString());
            map.put("languageType",channel.getLanguageType().toString());
            responseVO.setSuccess(true);
            responseVO.setTicket(null);
            responseVO.setErrorCode(200);
            responseVO.setBusinessResult(map);
        }
        return responseVO;
    }

    @RequestMapping("/common/local.html")
    public ResponseVO localInit(@RequestParam(name = "name") String name,@RequestParam("languageType") Integer languageType){
        LocalePrompt localCache = LocalCache.getLocalCache(name, languageType);
        //封装视图
        ResponseVO responseVO = new ResponseVO();
        if (localCache==null){
            return responseVO;
        }else {
            HashMap<String, String> map = new HashMap<>();
            map.put("id",localCache.getId().toString());
            map.put("name",localCache.getName());
            map.put("code",localCache.getCode());
            map.put("value",localCache.getValue());
            map.put("languageType",localCache.getLanguageType().toString());
            responseVO.setSuccess(true);
            responseVO.setTicket(null);
            responseVO.setErrorCode(200);
            responseVO.setBusinessResult(map);
        }
        return responseVO;
    }

}
